<?php

namespace cccmvc;

use cccmvc\exception\DatabaseException;

class Database
{
    public \PDO $pdo;

    /**
     * @throws DatabaseException
     */
    public function __construct($config)
    {
        $dsn = $config['dsn'] ?? '';
        $username = $config['username'] ?? '';
        $passwd = $config['password'] ?? '';

        try {
            $this->pdo = new \PDO($dsn, $username, $passwd);
        } catch (\Throwable $e) {
            throw new DatabaseException();
        }
    }

    public function prepare($sql)
    {
        return $this->pdo->prepare($sql);
    }
}